package com.imti.mall.product.mapper;

import com.imti.mall.model.pms.pojo.PmsProductCategoryAttributeRelation;
import com.imti.mall.model.pms.vo.PmsProductAttributeVo;
import org.apache.ibatis.jdbc.SQL;

/**
 * ClassName: PmsProductCategoryAttributeRelationDynaSqlProvider
 * Description:
 * date: 2022/9/19 10:13
 *
 * @author: youhun
 * @version:
 * @since JDK 1.8
 */
public class PmsProductCategoryAttributeRelationDynaSqlProvider {




    public String updatePmsProductCategoryAttributeRelation(final PmsProductCategoryAttributeRelation pmsProductCategoryAttributeRelation){
        return new SQL(){
            {
                UPDATE(" `pms_product_attribute` ");
                if(pmsProductCategoryAttributeRelation.getProductCategoryId()!=null){
                    SET(" product_category_id=#{productCategoryId} ");
                }
                if(pmsProductCategoryAttributeRelation.getProductAttributeId()!=null){
                    SET(" product_attribute_id=#{productAttributeId} ");
                }
                WHERE(" id=#{id} ");
            }
        }.toString();
    }



    public String findPmsProductCategoryAttributeRelation(final PmsProductCategoryAttributeRelation pmsProductCategoryAttributeRelation){
        return new SQL(){
            {
                SELECT(" id,product_category_id,product_attribute_id ");
                FROM(" pms_product_category_attribute_relation ");
                StringBuffer sb=new StringBuffer();
                if(pmsProductCategoryAttributeRelation!=null) {
                    if(pmsProductCategoryAttributeRelation.getProductCategoryId()!=null){
                        sb.append(" and product_category_id=#{productCategoryId} ");
                    }
                    if(pmsProductCategoryAttributeRelation.getProductAttributeId()!=null){
                        sb.append(" and product_attribute_id=#{productAttributeId} ");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
            }
        }.toString();
    }
}
